<template>
  <el-container style="height: 100vh;overflow: hidden;">
    <el-header direction="horizontal">
      <div class="left">
        <div class="logo">COCONUT</div>
      </div>
      <div class="right">
        <el-menu
            :default-active="activeMenu"
            @select="selectMenu"
            mode="horizontal"
            background-color="#2c3e50"
            text-color="#fff"
            active-text-color="#ffd04b">
          <el-menu-item index="org">
            <template #title>
              <el-icon>
                <Grid/>
              </el-icon>
              <span>组织管理</span>
            </template>
          </el-menu-item>
          <el-menu-item index="user">
            <template #title>
              <el-icon>
                <User/>
              </el-icon>
              <span>人员管理</span>
            </template>
          </el-menu-item>
          <el-menu-item index="role">
            <template #title>
              <el-icon>
                <Avatar/>
              </el-icon>
              <span>角色权限</span>
            </template>
          </el-menu-item>
          <el-menu-item index="dict">
            <template #title>
              <el-icon>
                <Management/>
              </el-icon>
              <span>数据字典</span>
            </template>
          </el-menu-item>
          <el-menu-item index="appclient">
            <template #title>
              <el-icon>
                <Platform/>
              </el-icon>
              <span>应用授权</span>
            </template>
          </el-menu-item>
          <el-menu-item index="record">
            <template #title>
              <el-icon>
                <Operation/>
              </el-icon>
              <span>定时调度</span>
            </template>
          </el-menu-item>
        </el-menu>
      </div>
      <div class="end">
        <el-menu
            @select="selectCenterMenu"
            mode="horizontal"
            :ellipsis="false"
            background-color="#2c3e50"
            text-color="#fff"
            active-text-color="#fff">
          <el-sub-menu index="center">
            <template #title>
              <el-icon>
                <Tools/>
              </el-icon>
              <span>我的工作台</span>
            </template>
            <el-menu-item index="logout">
              <template #title>
                <el-icon>
                  <Switch/>
                </el-icon>
                <span>注销</span>
              </template>
            </el-menu-item>
          </el-sub-menu>
        </el-menu>
      </div>
    </el-header>
    <el-main>
      <router-view v-slot="{ Component, route }">
        <transition :name="route.meta.transition">
          <keep-alive v-if="route.meta.keepAlive">
            <component :is="Component"/>
          </keep-alive>
          <component v-else :is="Component"/>
        </transition>
      </router-view>
    </el-main>
  </el-container>
</template>

<script>
export default {
  name: "Home",
  data() {
    return {
      activeMenu: "org"
    };
  },
  mounted() {
    this.activeMenu = this.$route.name || this.activeMenu;
  },
  methods: {
    selectMenu(key) {
      this.$router.push({name: key});
    },
    selectCenterMenu(key) {
      if (key === "logout") {
        this.$confirm("是否注销当前用户？", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.$http.post("/admin/sys/auth/logout", {}, () => {
            localStorage.removeItem(this.$config.authInfo);
            this.$router.replace({name: "login"});
          }, "注销成功！", true, true);
        }).catch(() => {
          //
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.el-container {
  height: 100%;
  overflow: hidden;

  .el-main {
    padding: 0;
    overflow: hidden;
    height: 0;
    flex: 1;
  }

  .el-header {
    background-color: #2c3e50;
    display: flex;
    flex-direction: row;
    margin: 0;
    padding: 0;

    .left {
      width: 250px;
      display: flex;
      align-items: center;
      justify-content: center;

      .logo {
        height: 40px;
        width: 180px;
        background-color: white;
        border-radius: 5px;
        line-height: 40px;
        text-align: center;
        font-weight: bold;
        letter-spacing: 3px;
        color: #0896BA;
      }
    }

    .right {
      flex: 1;
    }

    .end {

    }
  }
}
</style>